<html>
 <head>
  <link href="./leetcode-problem.css" rel="stylesheet" type="text/css">
 </head>
 <body>
  <div class="question_difficulty">
   难度：Medium
  </div>
  <div>
   <h1 class="question_title">
    457. Circular Array Loop
   </h1>
   <p>
    You are given a
    <b>
     circular
    </b>
    array
    <code>
     nums
    </code>
    of positive and negative integers. If a number
    <i>
     k
    </i>
    at an index is positive, then move forward
    <i>
     k
    </i>
    steps. Conversely, if it's negative (-
    <i>
     k
    </i>
    ), move backward
    <i>
     k
    </i>
    &nbsp;steps. Since the array is circular, you may assume that the last element's next element is the first element, and the first element's previous element is the last element.
   </p>
   <p>
    Determine if there is a loop (or a cycle) in
    <code>
     nums
    </code>
    . A cycle must start and end at the same index and the cycle's length &gt; 1. Furthermore, movements in a cycle must all follow a single direction. In other words, a cycle must not consist of both forward and backward movements.
   </p>
   <p>
    &nbsp;
   </p>
   <p>
    <b>
     Example 1:
    </b>
   </p>
   <pre>
<b>Input:</b> [2,-1,1,2,2]
<b>Output:</b> true
<b>Explanation:</b> There is a cycle, from index 0 -&gt; 2 -&gt; 3 -&gt; 0. The cycle's length is 3.
</pre>
   <p>
    <b>
     Example 2:
    </b>
   </p>
   <pre>
<b>Input:</b> [-1,2]
<b>Output:</b> false
<b>Explanation:</b> The movement from index 1 -&gt; 1 -&gt; 1 ... is not a cycle, because the cycle's length is 1. By definition the cycle's length must be greater than 1.
</pre>
   <p>
    <b>
     Example 3:
    </b>
   </p>
   <pre>
<b>Input:</b> [-2,1,-1,-2,-2]
<b>Output:</b> false
<b>Explanation:</b> The movement from index 1 -&gt; 2 -&gt; 1 -&gt; ... is not a cycle, because movement from index 1 -&gt; 2 is a forward movement, but movement from index 2 -&gt; 1 is a backward movement. All movements in a cycle must follow a single direction.</pre>
   <p>
    &nbsp;
   </p>
   <p>
    <b>
     Note:
    </b>
   </p>
   <ol>
    <li>
     -1000 &le;&nbsp;nums[i] &le;&nbsp;1000
    </li>
    <li>
     nums[i] &ne;&nbsp;0
    </li>
    <li>
     1 &le;&nbsp;nums.length &le; 5000
    </li>
   </ol>
   <p>
    &nbsp;
   </p>
   <p>
    <b>
     Follow up:
    </b>
   </p>
   <p>
    Could you solve it in
    <b>
     O(n)
    </b>
    time complexity and&nbsp;
    <strong>
     O(1)
    </strong>
    extra space complexity?
   </p>
  </div>
  <div>
   <h1 class="question_title">
    457. 环形数组循环
   </h1>
   <p>
    给定一个含有正整数和负整数的
    <strong>
     环形
    </strong>
    数组&nbsp;
    <code>
     nums
    </code>
    。 如果某个索引中的数
    <em>
     k
    </em>
    &nbsp;为正数，则向前移动
    <em>
     k
    </em>
    &nbsp;个索引。相反，如果是负数 (
    <em>
     -k
    </em>
    )，则向后移动
    <em>
     k
    </em>
    &nbsp;个索引。因为数组是环形的，所以可以假设最后一个元素的下一个元素是第一个元素，而第一个元素的前一个元素是最后一个元素。
   </p>
   <p>
    确定
    <code>
     nums
    </code>
    &nbsp;中是否存在循环（或周期）。循环必须在相同的索引处开始和结束并且循环长度 &gt; 1。此外，一个循环中的所有运动都必须沿着同一方向进行。换句话说，一个循环中不能同时包括向前的运动和向后的运动。
    <br>
    &nbsp;
   </p>
   <p>
    <strong>
     示例 1：
    </strong>
   </p>
   <pre><strong>输入：</strong>[2,-1,1,2,2]
<strong>输出：</strong>true
<strong>解释：</strong>存在循环，按索引 0 -&gt; 2 -&gt; 3 -&gt; 0 。循环长度为 3 。
</pre>
   <p>
    <strong>
     示例 2：
    </strong>
   </p>
   <pre><strong>输入：</strong>[-1,2]
<strong>输出：</strong>false
<strong>解释：</strong>按索引 1 -&gt; 1 -&gt; 1 ... 的运动无法构成循环，因为循环的长度为 1 。根据定义，循环的长度必须大于 1 。
</pre>
   <p>
    <strong>
     示例 3:
    </strong>
   </p>
   <pre><strong>输入：</strong>[-2,1,-1,-2,-2]
<strong>输出：</strong>false
<strong>解释：</strong>按索引 1 -&gt; 2 -&gt; 1 -&gt; ... 的运动无法构成循环，因为按索引 1 -&gt; 2 的运动是向前的运动，而按索引 2 -&gt; 1 的运动是向后的运动。一个循环中的所有运动都必须沿着同一方向进行。</pre>
   <p>
    &nbsp;
   </p>
   <p>
    <strong>
     提示：
    </strong>
   </p>
   <ol>
    <li>
     -1000 &le;&nbsp;nums[i] &le;&nbsp;1000
    </li>
    <li>
     nums[i] &ne;&nbsp;0
    </li>
    <li>
     1 &le;&nbsp;nums.length &le; 5000
    </li>
   </ol>
   <p>
    &nbsp;
   </p>
   <p>
    <strong>
     进阶：
    </strong>
   </p>
   <p>
    你能写出时间时间复杂度为
    <strong>
     O(n)
    </strong>
    &nbsp;和额外空间复杂度为
    <strong>
     O(1)
    </strong>
    的算法吗？
   </p>
  </div>
 </body>
</html>